import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/views/layout'
Vue.use(VueRouter)

// 导入配置的动态路由
import base from './modules/base'
import companys from './modules/companys'
import questions from './modules/questions'
import subjects from './modules/subjects'
import articles from './modules/articles'

// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
// 静态路由
export const constRoutes = [{
  path: '/',
  component: Layout,
  meta: {
    title: '黑马面面'
  },
  redirect: '/dashboard',
  children: [{
    path: 'dashboard',
    component: () => import('@/views/dashboard'),
    meta: {
      title: '欢迎您'
    }
  }
    // 传统思路是所有的子级路由都在一个配置里
    // 下面是新思路
  ]
},
{
  path: '/login',
  component: () => import("@/views/login"),
  meta: {
    title: '登录'
  }

},
{
  path: '/404',
  component: () => import('@/views/notfound')
},
]
// 动态路由
export const asyncRoutes = [
  base, companys, questions, subjects, articles
]
const router = new VueRouter({
  routes: [
     ...constRoutes
  ]
})

export default router
